package core;

import java.util.Properties;

import javax.print.attribute.standard.Sides;

import com.ibm.xtq.ast.parsers.xpath.tempconstructors.ILetClause;

import core.properties.DBProperty;
import core.properties.EnvProperty;
import core.properties.FirewallProperty;
import core.properties.PropertyReader;
import core.properties.RegisteredProperty;

/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class PropertiesContainer implements EnvProperty,FirewallProperty,DBProperty
{
	private static String resourceName = null;
	
	private String appVersion;
	
	private String username;
	
	private String password;
	
	private boolean passFirewall;
	
	private String fURL;
	
	private String fUsername;
	
	private String fUserPropValue;
	
	private String fUserPropName;
	
	private String fPassword;
	
	private String fPassPropValue;
	
	private String fPassPropName;
	
	private String fButtonName;
	
	private String fButtonValue;
	
	private String dbUsername;
	
	private String dbPassword;
	
	private String dbURL;
	
	private String dbDriver;
	
	
	private static PropertiesContainer propContainer = null;
	
	public static PropertiesContainer getInstance()
	{
		if(propContainer == null)
		{
			synchronized (PropertiesContainer.class) {
				if(propContainer == null)
				{
					propContainer = new PropertiesContainer();
				}
			}  
		}
		return propContainer;
	}
	
	public PropertiesContainer()
	{
		initEnvProperties();
		initDBProperties();
		initFirewallProperties();
	}
	
	private void initEnvProperties()
	{
		PropertyReader propReader = new PropertyReader();
		if(resourceName != null)
		{
			Properties properties = propReader.read(resourceName);
			
			String appVer = properties.getProperty(RegisteredProperty.APPVersion.name());
			String user = properties.getProperty(RegisteredProperty.username.name());
			String pass = properties.getProperty(RegisteredProperty.password.name());
			String passFirewall = properties.getProperty(RegisteredProperty.passFirewall.name());
			
			setAppVersion(appVer);
			setUsername(user);
			setPassword(pass);
			setPassFirewall(passFirewall);
		}
		else
		{
			throw new IllegalArgumentException("Env Property file is not set.");
		}
	}
	
	private void initDBProperties()
	{
		PropertyReader propReader = new PropertyReader();
		Properties properties = propReader.read(DBResourceBundle);
		
		String user = properties.getProperty(RegisteredProperty.DB_USERID.name());
		String pass = properties.getProperty(RegisteredProperty.DB_PASSWORD.name());
		String driver = properties.getProperty(RegisteredProperty.DB_DRIVER.name());
		String url = properties.getProperty(RegisteredProperty.DB_URL.name());
		
		setDBDriver(driver);
		setDBURL(url);
		setDBUsername(user);
		setDBPassword(pass);
	}
	
	private void initFirewallProperties()
	{
		PropertyReader propReader = new PropertyReader();
		Properties properties = propReader.read(FirewallRsourceBundle);
		
		String url = properties.getProperty(RegisteredProperty.F_URL.name());
		String user = properties.getProperty(RegisteredProperty.F_USERNAME.name());
		String pass = properties.getProperty(RegisteredProperty.F_PASSWORD.name());
		String uPropValue = properties.getProperty(RegisteredProperty.F_USERNAME_PROP_VALUE.name());
		String uPropName = properties.getProperty(RegisteredProperty.F_USERNAME_PROP_NAME.name());
		String pPropValue = properties.getProperty(RegisteredProperty.F_PASSWORD_PROP_VALUE.name());
		String pPropName = properties.getProperty(RegisteredProperty.F_PASSWORD_PROP_NAME.name());
		String bPropValue = properties.getProperty(RegisteredProperty.F_BUTTON_PROP_VALUE.name());
		String bPropName = properties.getProperty(RegisteredProperty.F_BUTTON_PROP_NAME.name());
		
		setFirewallURL(url);
		setFirewallUsername(user);
		setFirewallPassword(pass);
		setFirewallUPropValue(uPropValue);
		setFirewallUPropName(uPropName);
		setFirewallPPropValue(pPropValue);
		setFirewallPPropName(pPropName);
		setFirewallButPropName(bPropName);
		setFirewallButPropValue(bPropValue);
		
	}
	public static String getResourceName() {
		return resourceName;
	}

	public static void setResourceName(String resourceName) {
		PropertiesContainer.resourceName = resourceName;
	}

	@Override
	public String getAppVersion() {
		return this.appVersion;
	}

	@Override
	public String getPassword() {
		return this.password;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public void setAppVersion(String appVersion) {
		this.appVersion = appVersion;
	}

	@Override
	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public void setUsername(String username) {
		this.username = username;
	}

	@Override
	public String getFirewallPPropName() {
		return fPassPropName;
	}

	@Override
	public String getFirewallPPropValue() {
		return fPassPropValue;
	}

	@Override
	public String getFirewallPassword() {
		return fPassword;
	}

	@Override
	public String getFirewallUPropName() {
		return fUserPropName;
	}

	@Override
	public String getFirewallUPropValue() {
		return fUserPropValue;
	}

	@Override
	public String getFirewallURL() {
		return fURL;
	}

	@Override
	public String getFirewallUsername() {
		return fUsername;
	}

	@Override
	public void setFirewallPPropName(String propName) {
		this.fPassPropName = propName;
	}

	@Override
	public void setFirewallPPropValue(String propValue) {
		this.fPassPropValue = propValue;
	}

	@Override
	public void setFirewallPassword(String password) {
		this.fPassword = password;
	}

	@Override
	public void setFirewallUPropName(String propName) {
		this.fUserPropName = propName;
	}

	@Override
	public void setFirewallUPropValue(String propValue) {
		this.fUserPropValue = propValue;
	}

	@Override
	public void setFirewallURL(String url) {
		this.fURL = url;
	}

	@Override
	public void setFirewallUsername(String username) {
		this.fUsername = username;
	}

	@Override
	public String getDBDriver() {
		return dbDriver;
	}

	@Override
	public String getDBPassword() {
		return dbPassword;
	}

	@Override
	public String getDBURL() {
		return dbURL;
	}

	@Override
	public String getDBUsername() {
		return dbUsername;
	}

	@Override
	public void setDBDriver(String db_driver) {
		this.dbDriver = db_driver;
	}

	@Override
	public void setDBPassword(String password) {
		this.dbPassword = password;
	}

	@Override
	public void setDBURL(String db_url) {
		this.dbURL = db_url;
	}

	@Override
	public void setDBUsername(String userid) {
		this.dbUsername = userid;
	}

	@Override
	public String getFirewallButPropName() {
		return fButtonName;
	}

	@Override
	public String getFirewallButPropValue() {
		return fButtonValue;
	}

	@Override
	public void setFirewallButPropName(String propName) {
		this.fButtonName = propName;
		
	}

	@Override
	public void setFirewallButPropValue(String propValue) {
		this.fButtonValue = propValue;
		
	}

	@Override
	public boolean getPassFirewall() {
		return passFirewall;
	}

	@Override
	public void setPassFirewall(String passFirewall) {
		this.passFirewall = Boolean.parseBoolean(passFirewall);
	}

}

